﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Interop;

namespace WlanDesignDll
{
    class BuildingSetCommandHandler : System.Windows.Input.ICommand
    {
        #region ICommand 成员

        public bool CanExecute(object parameter)
        {
            return true;
            //throw new NotImplementedException();
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            bool ret;
            System.Threading.Mutex m = new System.Threading.Mutex(true, System.Windows.Forms.Application.ProductName, out   ret);
            if (ret)
            {
                AcadApplication acAppComObj = null;
                const string strProgId = "AutoCAD.Application.18";
                // Get a running instance of AutoCAD
                try
                {
                    acAppComObj = (AcadApplication)Marshal.GetActiveObject(strProgId);
                }
                catch // An error occurs if no instance is running
                {
                    try
                    {
                        // Create a new instance of AutoCAD
                        acAppComObj = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);

                    }
                    catch
                    {
                        // If an instance of AutoCAD is not created then message and exit
                        System.Windows.Forms.MessageBox.Show("Instance of 'AutoCAD.Application'" + " could not be created.");
                        return;
                    }
                }
                AcadDocument acDocComObj;

                acDocComObj = acAppComObj.ActiveDocument;
                acDocComObj.SendCommand("BuildingSet ");


                //throw new NotImplementedException();
            }
            else
            {
            }
        }
        

        #endregion
    }
}
